package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.core.AreaService;
import com.fwtai.service.web.AllUserService;
import com.fwtai.service.web.KnowledgeService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 系统用户控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2021-11-10 15:45:05
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/allUser")
public class AllUserController{

  @Resource
  private AllUserService alluserService;

  @Resource
  private KnowledgeService knowledgeService;

  @Resource
  private AreaService areaService;

  /**获取数据*/
  @PreAuthorize("hasAuthority('allUser_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(alluserService.listData(new PageFormData(request)),response);
  }

  @PreAuthorize("hasAuthority('allUser_btn_export')")
  @GetMapping("/exportExcel")
  public void exportExcel(final HttpServletRequest request,final HttpServletResponse response){
    alluserService.queryDataExport(request,response);
  }

  @PreAuthorize("hasAuthority('allUser_btn_domainList')")
  @GetMapping("/getDomainList")
  public void getDomainList(final HttpServletResponse response){
    ToolClient.responseJson(knowledgeService.getDomainList(),response);
  }

  /**获取模板数据*/
  @PreAuthorize("hasAuthority('allUser_btn_listSearch')")
  @GetMapping("/getListSearch")
  public void getListSearch(final String value,final HttpServletResponse response){
    ToolClient.responseJson(alluserService.getListSearch(value),response);
  }

  /**获取区域数据*/
  @PreAuthorize("hasAuthority('allUser_btn_queryAreaSelect')")
  @GetMapping("/queryArea")
  public void queryArea(final String pid,final HttpServletResponse response){
    ToolClient.responseJson(areaService.getAreaOpts(pid),response);
  }

  /**批量发送短信,以复选框发送*/
  @PreAuthorize("hasAuthority('allUser_btn_sendSms')")
  @PostMapping("/addSendSms")
  public void addSendSms(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(alluserService.addSendSms(request),response);
  }
}